//
//  UIView+samFrame.m
//  CRM
//
//  Created by sam lau on 17/3/21.
//  Copyright © 2017年 AP-EC. All rights reserved.
//

#import "UIView+samFrame.h"

@implementation UIView (samFrame)

//width
- (void)setSam_width:(CGFloat)sam_width{
    
    CGRect frame = self.frame;
    frame.size.width = sam_width;
    self.frame = frame;
}
- (CGFloat)sam_width{
    return self.frame.size.width;
}

//height
- (void)setSam_height:(CGFloat)sam_height{
    
    CGRect frame = self.frame;
    frame.size.height = sam_height;
    self.frame = frame;
}
- (CGFloat)sam_height{
    return self.frame.size.height;
}
//x
-(void)setSam_x:(CGFloat)sam_x {
    CGRect frame = self.frame;
    frame.origin.x = sam_x;
    self.frame = frame;
}
- (CGFloat)sam_x{
    return self.frame.origin.x;
}

//y

-(void)setSam_y:(CGFloat)sam_y {
    CGRect frame = self.frame;
    frame.origin.y = sam_y;
    self.frame = frame;
}
-(CGFloat)sam_y {
    return self.frame.origin.y;
}

//centerX
- (void)setSam_centerX:(CGFloat)sam_centerX {
    CGPoint center = self.center;
    center.x = sam_centerX;
    self.center = center;
}
- (CGFloat)sam_centerX{
    return self.center.x;
}

//centerY
- (void)setSam_centerY:(CGFloat)sam_centerY {
    CGPoint center = self.center;
    center.y = sam_centerY;
    self.center = center;
}
- (CGFloat)sam_centerY{
    return self.center.y;
}


//maxX
-(CGFloat)sam_maxX{
    return self.frame.origin.x + self.frame.size.width;
}
-(void)setSam_maxX:(CGFloat)sam_maxX{
    CGRect frame = self.frame;
    frame.origin.x = sam_maxX -frame.size.width;
    self.frame = frame;
}

//maxY

-(CGFloat)sam_maxY{
    return self.frame.origin.y + self.frame.size.height;
}
-(void)setSam_maxY:(CGFloat)sam_maxY{
    CGRect frame = self.frame;
    frame.origin.y = sam_maxY - frame.size.height;
    self.frame = frame;
}

//origin
-(CGPoint)sam_origin{
    return self.frame.origin;
}
-(void)setSam_origin:(CGPoint)sam_origin{
    CGRect frame = self.frame;
    frame.origin = sam_origin;
    self.frame = frame;
}

//size
-(CGSize)sam_size{
    return  self.frame.size;
}
-(void)setSam_size:(CGSize)sam_size{
    CGRect frame = self.frame;
    frame.size = sam_size;
    self.frame = frame;
}

//获取该视图的控制器
- (UIViewController*) viewController{
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

//删除当前视图内的所有子视图
- (void) removeChildViews{
    for (UIView *cv in self.subviews) {
        [cv removeFromSuperview];
    }
}
//删除tableview底部多余横线
- (void)setExtraCellLineHidden: (UITableView *)tableView
{
    
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
}


@end
